//$Id: Hibernate.java,v 1.19 2005/11/30 14:32:47 maxcsaucdk Exp $
package org.mk;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.Serializable;
import java.sql.Blob;
import java.sql.Clob;
import java.util.Iterator;
import java.util.Properties;

import net.sf.cglib.transform.impl.InterceptFieldEnabled;

//import org.mk.collection.PersistentCollection;
//import org.mk.engine.HibernateIterator;
//import org.mk.intercept.FieldInterceptor;
//import org.mk.lob.BlobImpl;
//import org.mk.lob.ClobImpl;
//import org.mk.lob.SerializableBlob;
//import org.mk.lob.SerializableClob;
//import org.mk.proxy.HibernateProxy;
//import org.mk.proxy.LazyInitializer;
//import org.mk.type.AnyType;
//import org.mk.type.BigDecimalType;
//import org.mk.type.BigIntegerType;
//import org.mk.type.BinaryType;
//import org.mk.type.BlobType;
//import org.mk.type.BooleanType;
//import org.mk.type.ByteType;
//import org.mk.type.CalendarDateType;
//import org.mk.type.CalendarType;
//import org.mk.type.CharacterType;
//import org.mk.type.ClassType;
//import org.mk.type.ClobType;
//import org.mk.type.CompositeCustomType;
//import org.mk.type.CurrencyType;
//import org.mk.type.CustomType;
//import org.mk.type.DateType;
//import org.mk.type.DoubleType;
//import org.mk.type.FloatType;
import org.mk.type.IntegerType;
//import org.mk.type.LocaleType;
//import org.mk.type.LongType;
//import org.mk.type.ManyToOneType;
import org.mk.type.NullableType;
//import org.mk.type.SerializableType;
//import org.mk.type.ShortType;
import org.mk.type.StringType;
//import org.mk.type.TextType;
//import org.mk.type.TimeType;
//import org.mk.type.TimeZoneType;
//import org.mk.type.TimestampType;
//import org.mk.type.TrueFalseType;
//import org.mk.type.Type;
//import org.mk.type.YesNoType;
//import org.mk.usertype.CompositeUserType;

/**
 * <ul>
 * <li>Provides access to the full range of Hibernate built-in types. <tt>Type</tt>
 * instances may be used to bind values to query parameters.
 * <li>A factory for new <tt>Blob</tt>s and <tt>Clob</tt>s.
 * <li>Defines static methods for manipulation of proxies.
 * </ul>
 *
 * @author Gavin King
 * @see java.sql.Clob
 * @see java.sql.Blob
 * @see org.mk.type.Type
 */

public  class PostgresType extends DataType{

//	/**
//	 * Hibernate <tt>long</tt> type.
//	 */
//	public static final NullableType LONG = new LongType();
//	/**
//	 * Hibernate <tt>short</tt> type.
//	 */
//	public static final NullableType SHORT = new ShortType();
	/**
	 * Hibernate <tt>integer</tt> type.
	 */
	public static final NullableType INTEGER = new IntegerType();
//	/**
//	 * Hibernate <tt>byte</tt> type.
//	 */
//	public static final NullableType BYTE = new ByteType();
//	/**
//	 * Hibernate <tt>float</tt> type.
//	 */
//	public static final NullableType FLOAT = new FloatType();
//	/**
//	 * Hibernate <tt>double</tt> type.
//	 */
//	public static final NullableType DOUBLE = new DoubleType();
//	/**
//	 * Hibernate <tt>character</tt> type.
//	 */
//	public static final NullableType CHARACTER = new CharacterType();
	/**
	 * MK <tt>string</tt> type.
	 */
	public static final NullableType STRING = new StringType();
//	/**
//	 * Hibernate <tt>time</tt> type.
//	 */
//	public static final NullableType TIME = new TimeType();
//	/**
//	 * Hibernate <tt>date</tt> type.
//	 */
//	public static final NullableType DATE = new DateType();
//	/**
//	 * Hibernate <tt>timestamp</tt> type.
//	 */
//	public static final NullableType TIMESTAMP = new TimestampType();
//	/**
//	 * Hibernate <tt>boolean</tt> type.
//	 */
//	public static final NullableType BOOLEAN = new BooleanType();
//	/**
//	 * Hibernate <tt>true_false</tt> type.
//	 */
//	public static final NullableType TRUE_FALSE = new TrueFalseType();
//	/**
//	 * Hibernate <tt>yes_no</tt> type.
//	 */
//	public static final NullableType YES_NO = new YesNoType();
//	/**
//	 * Hibernate <tt>big_decimal</tt> type.
//	 */
//	public static final NullableType BIG_DECIMAL = new BigDecimalType();
//	/**
//	 * Hibernate <tt>big_integer</tt> type.
//	 */
//	public static final NullableType BIG_INTEGER = new BigIntegerType();
//	/**
//	 * Hibernate <tt>binary</tt> type.
//	 */
//	public static final NullableType BINARY = new BinaryType();
//	/**
//	 * Hibernate <tt>text</tt> type.
//	 */
//	public static final NullableType TEXT = new TextType();
//	/**
//	 * Hibernate <tt>blob</tt> type.
//	 */
//	public static final Type BLOB = new BlobType();
//	/**
//	 * Hibernate <tt>clob</tt> type.
//	 */
//	public static final Type CLOB = new ClobType();
//	/**
//	 * Hibernate <tt>calendar</tt> type.
//	 */
//	public static final NullableType CALENDAR = new CalendarType();
//	/**
//	 * Hibernate <tt>calendar_date</tt> type.
//	 */
//	public static final NullableType CALENDAR_DATE = new CalendarDateType();
//	/**
//	 * Hibernate <tt>locale</tt> type.
//	 */
//	public static final NullableType LOCALE = new LocaleType();
//	/**
//	 * Hibernate <tt>currency</tt> type.
//	 */
//	public static final NullableType CURRENCY = new CurrencyType();
//	/**
//	 * Hibernate <tt>timezone</tt> type.
//	 */
//	public static final NullableType TIMEZONE = new TimeZoneType();
//	/**
//	 * Hibernate <tt>class</tt> type.
//	 */
//	public static final NullableType CLASS = new ClassType();
//	/**
//	 * Hibernate <tt>serializable</tt> type.
//	 */
//	public static final NullableType SERIALIZABLE = new SerializableType( Serializable.class );
//	/**
//	 * Hibernate <tt>object</tt> type.
//	 */
//	public static final Type OBJECT = new AnyType();


//	/**
//	 * Cannot be instantiated.
//	 */
//	private MySQLType() {
//		throw new UnsupportedOperationException();
//	}

//	/**
//	 * A Hibernate <tt>serializable</tt> type.
//	 */
//	public static Type serializable(Class serializableClass) {
//		return new SerializableType( serializableClass );
//	}
//
//	/**
//	 * A Hibernate <tt>any</tt> type.
//	 *
//	 * @param metaType       a type mapping <tt>java.lang.Class</tt> to a single column
//	 * @param identifierType the entity identifier type
//	 * @return the Type
//	 */
//	public static Type any(Type metaType, Type identifierType) {
//		return new AnyType( metaType, identifierType );
//	}
//
//	/**
//	 * A Hibernate persistent object (entity) type.
//	 *
//	 * @param persistentClass a mapped entity class
//	 */
//	public static Type entity(Class persistentClass) {
//		// not really a many-to-one association *necessarily*
//		return new ManyToOneType( persistentClass.getName() );
//	}
//
//	/**
//	 * A Hibernate persistent object (entity) type.
//	 *
//	 * @param entityName a mapped entity class
//	 */
//	public static Type entity(String entityName) {
//		// not really a many-to-one association *necessarily*
//		return new ManyToOneType( entityName );
//	}
//
//	/**
//	 * A Hibernate custom type.
//	 *
//	 * @param userTypeClass a class that implements <tt>UserType</tt>
//	 */
//	public static Type custom(Class userTypeClass) throws HibernateException {
//		return custom( userTypeClass, null );
//	}
//
//	/**
//	 * A Hibernate parameterizable custom type.
//	 *
//	 * @param userTypeClass   a class that implements <tt>UserType and ParameterizableType</tt>
//	 * @param parameterNames  the names of the parameters passed to the type
//	 * @param parameterValues the values of the parameters passed to the type. They must match
//	 *                        up with the order and length of the parameterNames array.
//	 */
//	public static Type custom(Class userTypeClass, String[] parameterNames, String[] parameterValues)
//			throws HibernateException {
//		Properties parameters = new Properties();
//		for ( int i = 0; i < parameterNames.length; i++ ) {
//			parameters.setProperty( parameterNames[i], parameterValues[i] );
//		}
//		return custom( userTypeClass, parameters );
//	}
//
//	/**
//	 * A Hibernate parameterizable custom type.
//	 *
//	 * @param userTypeClass a class that implements <tt>UserType and ParameterizableType</tt>
//	 * @param parameters    the parameters as a collection of name/value pairs
//	 */
//	public static Type custom(Class userTypeClass, Properties parameters)
//			throws HibernateException {
//		if ( CompositeUserType.class.isAssignableFrom( userTypeClass ) ) {
//			CompositeCustomType type = new CompositeCustomType( userTypeClass, parameters );
//			return type;
//		}
//		else {
//			CustomType type = new CustomType( userTypeClass, parameters );
//			return type;
//		}
//	}
//
//	/**
//	 * Force initialization of a proxy or persistent collection.
//	 * <p/>
//	 * Note: This only ensures intialization of a proxy object or collection;
//	 * it is not guaranteed that the elements INSIDE the collection will be initialized/materialized.
//	 *
//	 * @param proxy a persistable object, proxy, persistent collection or <tt>null</tt>
//	 * @throws HibernateException if we can't initialize the proxy at this time, eg. the <tt>Session</tt> was closed
//	 */
//	public static void initialize(Object proxy) throws HibernateException {
//		if ( proxy == null ) {
//			return;
//		}
//		else if ( proxy instanceof HibernateProxy ) {
//			( ( HibernateProxy ) proxy ).getHibernateLazyInitializer().initialize();
//		}
//		else if ( proxy instanceof PersistentCollection ) {
//			( ( PersistentCollection ) proxy ).forceInitialization();
//		}
//	}
//
//	/**
//	 * Check if the proxy or persistent collection is initialized.
//	 *
//	 * @param proxy a persistable object, proxy, persistent collection or <tt>null</tt>
//	 * @return true if the argument is already initialized, or is not a proxy or collection
//	 */
//	public static boolean isInitialized(Object proxy) {
//		if ( proxy instanceof HibernateProxy ) {
//			return !( ( HibernateProxy ) proxy ).getHibernateLazyInitializer().isUninitialized();
//		}
//		else if ( proxy instanceof PersistentCollection ) {
//			return ( ( PersistentCollection ) proxy ).wasInitialized();
//		}
//		else {
//			return true;
//		}
//	}
//
//	/**
//	 * Get the true, underlying class of a proxied persistent class. This operation
//	 * will initialize a proxy by side-effect.
//	 *
//	 * @param proxy a persistable object or proxy
//	 * @return the true class of the instance
//	 * @throws HibernateException
//	 */
//	public static Class getClass(Object proxy) {
//		if ( proxy instanceof HibernateProxy ) {
//			return ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer()
//					.getImplementation()
//					.getClass();
//		}
//		else {
//			return proxy.getClass();
//		}
//	}
//
//	/**
//	 * Create a new <tt>Blob</tt>. The returned object will be initially immutable.
//	 *
//	 * @param bytes a byte array
//	 * @return the Blob
//	 */
//	public static Blob createBlob(byte[] bytes) {
//		return new SerializableBlob( new BlobImpl( bytes ) );
//	}
//
//	/**
//	 * Create a new <tt>Blob</tt>. The returned object will be initially immutable.
//	 *
//	 * @param stream a binary stream
//	 * @param length the number of bytes in the stream
//	 * @return the Blob
//	 */
//	public static Blob createBlob(InputStream stream, int length) {
//		return new SerializableBlob( new BlobImpl( stream, length ) );
//	}
//
//	/**
//	 * Create a new <tt>Blob</tt>. The returned object will be initially immutable.
//	 *
//	 * @param stream a binary stream
//	 * @return the Blob
//	 * @throws IOException
//	 */
//	public static Blob createBlob(InputStream stream) throws IOException {
//		return new SerializableBlob( new BlobImpl( stream, stream.available() ) );
//	}
//
//	/**
//	 * Create a new <tt>Clob</tt>. The returned object will be initially immutable.
//	 *
//	 * @param string a <tt>String</tt>
//	 */
//	public static Clob createClob(String string) {
//		return new SerializableClob( new ClobImpl( string ) );
//	}
//
//	/**
//	 * Create a new <tt>Clob</tt>. The returned object will be initially immutable.
//	 *
//	 * @param reader a character stream
//	 * @param length the number of characters in the stream
//	 */
//	public static Clob createClob(Reader reader, int length) {
//		return new SerializableClob( new ClobImpl( reader, length ) );
//	}
//
//	/**
//	 * Close an <tt>Iterator</tt> created by <tt>iterate()</tt> immediately,
//	 * instead of waiting until the session is closed or disconnected.
//	 *
//	 * @param iterator an <tt>Iterator</tt> created by <tt>iterate()</tt>
//	 * @throws HibernateException
//	 * @see org.mk.Query#iterate(java.lang.String)
//	 * @see Query#iterate()
//	 */
//	public static void close(Iterator iterator) throws HibernateException {
//		if ( iterator instanceof HibernateIterator ) {
//			( ( HibernateIterator ) iterator ).close();
//		}
//		else {
//			throw new IllegalArgumentException( "not a Hibernate iterator" );
//		}
//	}
//
//	/**
//	 * Check if the property is initialized. If the named property does not exist
//	 * or is not persistent, this method always returns <tt>true</tt>.
//	 *
//	 * @param entity a persistable object
//	 * @param propertyName the name of a persistent attribute of the object
//	 * @return true if the named property of the object is not listed as uninitialized
//	 * @return false if the object is an uninitialized proxy, or the named property is uninitialized
//	 */
//	public static boolean isPropertyInitialized(Object proxy, String propertyName) {
//		
//		Object entity;
//		if ( proxy instanceof HibernateProxy ) {
//			LazyInitializer li = ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer();
//			if ( li.isUninitialized() ) {
//				return false;
//			}
//			else {
//				entity = li.getImplementation();
//			}
//		}
//		else {
//			entity = proxy;
//		}
//		
//		if ( entity instanceof InterceptFieldEnabled ) {
//			FieldInterceptor fieldInterceptor = FieldInterceptor.getFieldInterceptor(entity);
//			return fieldInterceptor != null && fieldInterceptor.isInitialized( propertyName );
//		}
//		else {
//			return true;
//		}
//		
//	}

}






